﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class Requests : System.Web.UI.Page
{
    BankDataDataContext db = new BankDataDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Roles.IsUserInRole("Operator"))
        {
            Response.Redirect("~/Account/Login.aspx");
        }
    }

    protected void RequestListGridView_SelectedIndexChanged(object sender, EventArgs e)
    {
        string creditRequestId = RequestListGridView.DataKeys[RequestListGridView.SelectedIndex]["CreditRequestId"].ToString();
        var requests = from request in db.CreditRequests where request.CreditRequestId == Convert.ToInt32(creditRequestId) select request;
        if (requests.First().RequestStatusId == 0)
        {
            Session.Add("requestId", creditRequestId);
            Response.Redirect("~/Operator/ReviewRequest.aspx");
        }
        else
        {
            Response.Redirect("~/Operator/Requests.aspx");
        }
    }
}